package com.qixiucoding.pojo.rule;

import com.qixiucoding.baseRule.abs.AbstractRule;
import com.qixiucoding.pojo.NationalityRuleDto;
import com.qixiucoding.pojo.RuleDto;

import static com.qixiucoding.baseRule.abs.RuleConstant.MATCH_ADDRESS_START;
import static com.qixiucoding.baseRule.abs.RuleConstant.MATCH_NATIONALILY_START;

/**
 * @Description TODO
 * @Author longhj
 * @Date 2022/01/16 星期日 0:42
 */
public class NotionalityRule extends AbstractRule {
    @Override
    protected <T> T convert(RuleDto dto) {
        NationalityRuleDto nationalityRuleDto = new NationalityRuleDto();
        if (dto.getAddress().startsWith(MATCH_ADDRESS_START)) {
            nationalityRuleDto.setNationality(MATCH_NATIONALILY_START);
        }
        return (T) nationalityRuleDto;

    }

    @Override
    protected <T> boolean executeRule(T t) {
        System.out.println("NationalityRule invoker");
        NationalityRuleDto nationalityRuleDto = (NationalityRuleDto) t;
        if (nationalityRuleDto.getNationality().startsWith(MATCH_NATIONALILY_START)) {
            return true;
        }
        return false;
    }
}
